<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('公文签收列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>发文号：</label>
                            <input id="docOrder" type="text" name="docOrder"/>
                        </li>
                        <li>
                            <label>公文标题：</label>
                            <input id="docTitle" type="text" name="docTitle"/>
                        </li>
                        <li>
                            <label>发文日期：</label>
                            <input id="docDate" type="text" class="time-input" placeholder="请选择发文日期" name="docDate"/>
                        </li>
                        <li>
                            <label>签收情况：</label>
                            <select name="status" id="choose-sign" placeholder="请选择签收情况">
                                <option value="">---</option>
                                <option value="1">已签收</option>
                                <option value="0">未签收</option>
                            </select>
                        </li>
                        <li><!---->
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="docManager:manager:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="docManager:manager:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="docManager:manager:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="docManager:manager:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('docManager:manager:edit')}]];
    var removeFlag = [[${@permission.hasPermi('docManager:manager:remove')}]];
    var prefix = ctx + "docManager/manager";
    var sendFlag = [[${@permission.hasPermi('docManager:manager:sendDoc')}]];

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            sendUrl: prefix + "/sendDoc",
            signUrl: prefix + "signDoc",
            modalName: "公文签收",
            columns: [{
                checkbox: true
            }, {
                field: 'id',
                title: 'NO',
                visible: false
            }, {
                field: 'docOrder',
                title: '发文号'
            }, {
                field: 'docTitle',
                title: '公文标题',
            }, {
                field: 'docUrl',
                title: '公文保存地址',
                visible: false
            }, {
                field: 'deptId',
                title: '发文部门id',
                visible: false
            }, {
                field: 'deptName',
                title: '部门',
                formatter: function (value, row, index) {
                    console.log(value);
                    console.log(row);
                    console.log(index);
                    return row.dept.deptName;
                }
            }, {
                field: 'docDate',
                title: '发文日期'
            }, {
                field: 'status',
                title: '签收情况',
                visible: true
            }, {
                field: 'sendStatus',
                title: '转发情况',
                visible: true
            }, {
                title: '操作',
                align: 'center',
                formatter: function (value, row, index) {
                    var actions = [];
                    if (row.status === 1) {
                        actions.push('<a class="badge badge-info"><i class="fa fa-edit"></i> 已签收  </a>');
                        if (row.sendStatus===1){
                            //已转发
                            // actions.push('<a class="btn btn-primary btn-xs" onclick=$.modal.msg("默认提示")><i class="fa fa-edit"></i> 转发情况</a>');
                            actions.push('<a class="btn btn-success btn-xs ' + '" href="javascript:void(0)" onclick="$.modal.open(\'' + "转发" + '\',\'' + prefix +"/"+row.id + "/sendDoc/" + '\')"><i class="fa fa-edit"></i>转发详情</a> ');
                        }else {
                            actions.push('<a class="btn btn-success btn-xs" onclick=$.modal.msg("无需转发")><i class="fa fa-edit"></i> 转发</a>');
                        }
                    } else {
                        actions.push('<a class="btn btn-success btn-xs" onclick=confirmSigned('+JSON.stringify(row)+')><i class="fa fa-edit"></i> 签收</a>  ');
                        // actions.push('<a class="btn btn-success btn-xs disabled" onclick=$.modal.msg("默认提示")><i class="fa fa-edit" ></i> 转发</a>');
                        actions.push('<a class="btn btn-success btn-xs disabled' + sendFlag + '" href="javascript:void(0)" onclick="$.modal.open(\'' + "转发" + '\',\'' + prefix + "/addSendDoc/" + row.id + '\')"><i class="fa fa-edit"></i>转发</a> ');
        //var sendFlag = [[${@permission.hasPermi('docManager:manager:sendDoc')}]];

                    }
                    return actions.join('');
                }
            }]

        };
        $.table.init(options);
    });

    //确认签收动作
    function confirmSigned(row) {
        console.log(row);
        $.modal.confirm("确定签收" + row.docTitle + "吗？", function () {
            let url = prefix + "/signDoc";
            console.log(url);
            let data = {
                "docId": row.id,
                "deptId": row.deptId,
                "status": 1,
                "receiveDate": new Date(),
            };
            console.log(data);
            $.operate.submit(url, "post", "json", data);
            $.table.refresh();
        });
    }

</script>
</body>
</html>